
import java.awt.Component;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class Main extends JFrame implements ActionListener{
	private static final long serialVersionUID = 1L;

	JButton submit;
	JTextField parametru;
	JTextField rezultat;
	public void creareMediuGrafic(){
		JFrame fereastra = new JFrame();
		fereastra.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		fereastra.setAlwaysOnTop(true);
		Container suprafata = fereastra.getContentPane();
		suprafata.setLayout(new BoxLayout(suprafata, BoxLayout.Y_AXIS));
		JLabel info = new JLabel("Introduceti numarul in cifre romane:");
		info.setAlignmentX(Component.CENTER_ALIGNMENT);
		suprafata.add(info);
		parametru = new JTextField(12);
		parametru.setAlignmentX(Component.CENTER_ALIGNMENT);
		suprafata.add(parametru);
		submit = new JButton("Calculeaza");
		submit.setAlignmentX(Component.CENTER_ALIGNMENT);
		suprafata.add(submit);
		submit.addActionListener(this);
		rezultat = new JTextField(12);
		rezultat.setAlignmentX(Component.CENTER_ALIGNMENT);
		suprafata.add(rezultat);
		rezultat.setEditable(false);
		fereastra.pack();
		fereastra.setVisible(true);
	}
	public void actionPerformed(ActionEvent event){
		if (event.getSource().equals(submit)){
			rezultat.setText(calculat(parametru.getText()));
		}
	}
	public String calculat(String sirPars){
		Context rezultat = new Context();
		sirPars = sirPars.toUpperCase();
		Responsabil r,r1;
		r = r1 = new Cifre(this);
		r1 = r1.setNext(new Caractere(this));
		r1 = r1.setNext(new Ordine(this));

		r.test(sirPars);


		char[] lista = sirPars.toCharArray();
		for (char c : lista) {
			ExpresieAbstracta expr=new ExpresieNula();
			switch (c) {
			case 'I': 
				expr = new Unu();
				break;
			case 'V':
				expr = new Cinci();
				break;
			case 'X':
				expr = new Zece();
				break;
			case 'L':
				expr = new CinciZeci();
				break;
			case 'C':
				expr = new Suta();
				break;
			case 'D':
				expr = new CinciSute();
				break;
			case 'M':
				expr = new Mie();
				break;
			}
			expr.interpret(rezultat);
		}
		return String.valueOf(rezultat.returneazaFinal());
	}
	public static void main(String[]args){
		Main p = new Main();
		p.creareMediuGrafic();
	}
}
